<template>
	<div class="personnelList billShopList">
		<el-breadcrumb separator="/">
			<el-breadcrumb-item :to="{ path: '/' }">
				<i class="lh lh-caiwu fw_100"></i>
			</el-breadcrumb-item>
			<el-breadcrumb-item>账单结算</el-breadcrumb-item>
			<el-breadcrumb-item>商户结算单</el-breadcrumb-item>
		</el-breadcrumb>
		<div class="content_Box box-shadow mt_15">
			<div class="tableMaxBox">
				<div class="py_5 px_10">
					<el-form :inline="true" :model="ruleForm" class="form-inline mt_10" @keyup.enter.native="shearchBtn()">
						<el-form-item>
							<el-input size="mini" class="w_120" v-model="s_sn" placeholder="结算单编号"></el-input>
						</el-form-item>
						<el-form-item>
							<el-autocomplete
								size="mini"
								class="w_150"
								v-model="s_shop_name"
								:fetch-suggestions="querySearch"
								placeholder="店铺名称"
								:trigger-on-focus="true"
								clearable
								@select="handleSelect"
							></el-autocomplete>
						</el-form-item>
						<lh-agent-list @sendValue="setValue" :reset="agent_reset"></lh-agent-list>
						<el-form-item class="w_80">
							<el-select v-model="city_arr" placeholder="城市" @change="chengeCity">
								<el-option
									v-for="item in cityList"
									:key="item.id"
									:label="item.name"
									:value="`${item.id}|${item.name}`"
								></el-option>
							</el-select>
						</el-form-item>
						<el-form-item>
							<el-select
								size="mini"
								class="w_140"
								v-model="s_status"
								placeholder="状态"
								clearable
								multiple
								collapse-tags
							>
								<el-option label="已生成" value="10"></el-option>
								<el-option label="待支付" value="20"></el-option>
								<el-option label="已支付" value="30"></el-option>
								<el-option label="异常" value="70"></el-option>
							</el-select>
						</el-form-item>

						<el-form-item>
							<el-select size="mini" class="w_100" v-model="s_invoice_status" placeholder="发票状态" clearable>
								<el-option
									v-for="(item, index) in invoiceStatus"
									:key="index"
									:label="item.name"
									:value="item.code"
								></el-option>
							</el-select>
						</el-form-item>

						<el-form-item prop="datetime1">
							<el-date-picker
								size="mini"
								class="w_120i"
								type="date"
								value-format="yyyy-MM-dd"
								format="yyyy-MM-dd"
								placeholder="结算单开始日期"
								v-model="ruleForm.bill_date_start"
							></el-date-picker> </el-form-item
						>~
						<el-form-item prop="datetime2">
							<el-date-picker
								size="mini"
								class="w_120i"
								type="date"
								value-format="yyyy-MM-dd"
								format="yyyy-MM-dd"
								placeholder="结算单结束日期"
								v-model="ruleForm.bill_date_end"
							></el-date-picker>
						</el-form-item>

						<el-form-item>
							<el-select size="mini" class="w_140" v-model="s_time_type" placeholder="时间类型" clearable>
								<el-option label="创建时间" value="1"></el-option>
								<el-option label="更新时间" value="2"></el-option>
							</el-select>
						</el-form-item>

						<el-form-item prop="datetime1">
							<el-date-picker
								size="mini"
								class="w_180i"
								type="datetime"
								value-format="yyyy-MM-dd HH:mm:ss"
								format="yyyy-MM-dd HH:mm:ss"
								default-time="00:00:00"
								placeholder="开始时间"
								v-model="ruleForm.date1"
							></el-date-picker> </el-form-item
						>~
						<el-form-item prop="datetime2">
							<el-date-picker
								size="mini"
								class="w_180i"
								type="datetime"
								value-format="yyyy-MM-dd HH:mm:ss"
								format="yyyy-MM-dd HH:mm:ss"
								default-time="23:59:59"
								placeholder="结束时间"
								v-model="ruleForm.date2"
							></el-date-picker>
						</el-form-item>
						<el-button size="mini" type="primary" native-type="button" class="round-right" @click="shearchBtn"
							>搜索</el-button
						>
						<el-button size="mini" round @click="resetBtn">重置</el-button>
					</el-form>
					<div>
						<span class="addOK2" @click="downloadOrder()" style="width: 70px;">导出结算单</span>
						<span
							class="resetBtn mb_10"
							@click="batchPay(3)"
							style="width: 70px; margin-top: 10px; text-align: center;"
							v-if="!$route.query.sn"
						>
							批量确认
						</span>
						<span
							class="resetBtn mb_10"
							@click="batchPay(1)"
							style="width: 70px; margin-top: 10px; text-align: center;"
							v-if="!$route.query.sn"
						>
							批量已回款
						</span>
						<span
							class="resetBtn mb_10"
							@click="downloadDetail"
							style="width: 110px; margin-top: 10px; text-align: center;"
						>
							导出明细({{ alltotal }})
						</span>
					</div>
				</div>
				<template>
					<el-table :data="demandList" stripe @selection-change="handleSelectionChange">
						<el-table-column type="selection" :selectable="checkboxT" disabled="true"></el-table-column>
						<el-table-column type="index" prop="id" label="序号" width="60"></el-table-column>
						<el-table-column prop="sn" label="结算单编号" width="120">
							<template slot-scope="{ row }">
								<span>{{ row.sn }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="shop_name" label="店铺名称" width="200">
							<template slot-scope="{ row }">
								<span>{{ row.shop_name }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="agent_name" label="代理商" width="140"></el-table-column>
						<el-table-column prop="city_name" label="店铺城市" width="70">
							<template slot-scope="{ row }">
								<span>{{ row.city_name }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="bill_date_start" label="结算单开始日期" width="140">
							<template slot-scope="{ row }">
								<span>{{ $moment(row.bill_date_start).format('YYYY-MM-DD') }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="bill_date_end" label="结算单结束日期" width="140">
							<template slot-scope="{ row }">
								<span>{{ $moment(row.bill_date_end).format('YYYY-MM-DD') }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="type" label="结算单类型">
							<template slot-scope="{ row }">
								<span class="text-success" v-if="row.type == 1">应收结算单</span>
								<span class="text-success" v-if="row.type == 2">扣罚结算单</span>
							</template>
						</el-table-column>
						<el-table-column prop="amount" label="合计时长" width="100">
							<template slot-scope="{ row }">
								<span>{{ row.bill_total_hour }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="amount" label="结算单金额" width="100">
							<template slot-scope="{ row }">
								<span>{{ row.amount | filterNumber }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="count" label="数量">
							<template slot-scope="{ row }">
								<span class="u text-primary pointer" style="font-weight: bold;" @click="goToList(row)">{{
									row.count
								}}</span>
							</template>
						</el-table-column>
						<el-table-column prop="status" label="状态" width="120">
							<template slot-scope="{ row }">
								<span class="text-primary" v-if="row.status == 10">已生成</span>
								<span class="text-success" v-if="row.status == 20">待支付</span>
								<span class="text-info" v-if="row.status == 30">已支付</span>
								<span class="text-danger" v-if="row.status == 70">异常</span>
							</template>
						</el-table-column>
						<el-table-column prop="invoice_status_name" label="发票状态" width="120"></el-table-column>
						<el-table-column prop="add_time" label="创建时间" width="150"></el-table-column>
						<el-table-column prop="sn" label="支付记录编号" width="120">
							<template slot-scope="{ row }">
								<span>{{ row.settlement_sn }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="pay_time" label="回款时间" width="150"></el-table-column>
						<el-table-column prop="payer" label="回款人" width="100"></el-table-column>
						<el-table-column prop="remark" label="备注" width="150"></el-table-column>
						<el-table-column label="操作" width="300px" fixed="right" v-if="$route.query.sn == undefined">
							<template slot-scope="{ row }">
								<el-link type="info" class="InfoFont text-danger" :underline="false" @click="goToList(row)"
									>查看
								</el-link>
								<el-link
									v-if="row.status == 20"
									type="info"
									class="InfoFont text-danger"
									:underline="false"
									@click="goRecall(row)"
									>撤回
								</el-link>
								<el-link
									type="primary"
									class="InfoFont text-primary"
									:underline="false"
									v-if="row.status == 70"
									@click="regenerate(row)"
									>重新生成
								</el-link>
								<!-- 待确认状态下出现此按钮 -->
								<el-link
									type="info"
									class="InfoFont text-danger"
									:underline="false"
									v-if="row.status == 10"
									@click="Qr(row)"
									>确认结算单
								</el-link>
								<el-link type="info" class="InfoFont text-primary" :underline="false" @click="downloadOrdermini(row)"
									>导出明细
								</el-link>
								<el-link
									type="success"
									class="InfoFont text-primary"
									:underline="false"
									v-if="row.status == 10 || row.status == 20"
									@click="Hk(row)"
									>已回款
								</el-link>
								<el-link type="info" class="InfoFont text-primary" :underline="false" @click="goTorecord(row)"
									>操作记录
								</el-link>
							</template>
						</el-table-column>
						<el-table-column label="操作" width="70px" fixed="right" v-if="$route.query.sn != undefined">
							<template slot-scope="{ row }">
								<el-link type="info" class="InfoFont text-danger" :underline="false" @click="goToList(row)"
									>查看</el-link
								>
							</template>
						</el-table-column>
					</el-table>
					<div style="display: flex; flex-direction: row; flex-wrap: nowrap; justify-content: space-between;">
						<div style="height: 50px; line-height: 50px; margin-left: 20px;">
							已生成：<span style="color: red; font-weight: bold;">{{ statistics.created }}</span
							>元；待支付：<span style="color: red; font-weight: bold;">{{ statistics.accept }}</span
							>元；已支付：<span style="color: #000000; font-weight: bold;">{{ statistics.pay }}</span
							>元
						</div>
						<!-- 分页组件 -->
						<div style="margin-right: 20px;">
							<page :total="total" :pageNums="pageNum" :disableMountedFetch="true" @pagedata="onChildValue"></page>
						</div>
					</div>
				</template>
			</div>
		</div>
		<!-- 回款确认-弹框 -->
		<el-dialog :title="diaTitle" :visible.sync="ShowHk" width="560px" :close-on-click-modal="false">
			<div class="auditCentent">
				<div class="row-info clear">
					<div class="fl title-key">&nbsp;</div>
					<div class="fl list-cont">
						<span>确认已经收到结算单相关款项</span>
					</div>
				</div>
				<div class="row-info clear">
					<div class="fl title-key"><i class="lhadmin lhadmin-wujiaoxing"></i>备注</div>
					<div class="fl list-cont">
						<el-input type="textarea" :rows="4" :cols="32" v-model="remark" maxlength="250"></el-input>
					</div>
				</div>
			</div>
			<div slot="footer" class="dialog-footer">
				<span class="btnOK mr_20" @click="addCxBtn()">确 定</span>
				<span class="resetBtn" @click="hiddenRY()">取 消</span>
			</div>
		</el-dialog>
		<!-- 操作记录-弹框 -->
		<el-dialog :title="diaTitle" :visible.sync="cordTicket" width="600px" :close-on-click-modal="false">
			<div class="auditCentent">
				<div class="timeline" v-for="(item, index) in message" :key="index">
					<el-button type="success" class="fl" round size="mini" v-if="item.subject_type == 'created'"
						>创建结算单</el-button
					>
					<el-button type="success" class="fl" round size="mini" v-if="item.subject_type == 'accept'"
						>确认结算单</el-button
					>
					<el-button type="success" class="fl" round size="mini" v-if="item.subject_type == 'pay'">已回款</el-button>
					<el-button type="success" class="fl" round size="mini" v-if="item.subject_type == 'invoice'"
						>已开票</el-button
					>
					<el-button type="success" class="fl" round size="mini" v-if="item.subject_type == 'recreated'"
						>重新生成</el-button
					>
					<el-button type="success" class="fl" round size="mini" v-if="item.subject_type == 'withdrawal'"
						>结算单撤回</el-button
					>
					<span>{{ item.add_time }}</span>
					<span>{{ item.user_name }}</span>
				</div>
			</div>
			<div slot="footer" class="dialog-footer">
				<span class="resetBtn" @click="hiddenRY()">关 闭</span>
			</div>
		</el-dialog>
		<!-- 确认-弹框 -->
		<el-dialog :title="diaTitle" :visible.sync="ShowQr" width="560px" :close-on-click-modal="false">
			<div class="auditCentent">
				<div class="row-info clear">
					<div class="fl title-key">&nbsp;</div>
					<div class="fl list-cont">
						<span>结算单已经过商户和平台确认，无异议。</span>
					</div>
				</div>
				<div class="row-info clear">
					<div class="fl title-key"><i class="lhadmin lhadmin-wujiaoxing"></i>备注</div>
					<div class="fl list-cont">
						<el-input type="textarea" :rows="4" :cols="32" v-model="remark" maxlength="250"></el-input>
					</div>
				</div>
			</div>
			<div slot="footer" class="dialog-footer">
				<span class="btnOK mr_20" @click="addQrBtn()">确 定</span>
				<span class="resetBtn" @click="hiddenRY()">取 消</span>
			</div>
		</el-dialog>
		<!-- 撤回-弹框 -->
		<el-dialog title="提示" :visible.sync="showWithDrawal" width="560px" :close-on-click-modal="false">
			<div class="auditCentent">
				<div class="row-info clear">
					<div class="fl title-key">&nbsp;</div>
					<div class="fl list-cont">
						<span>确认要将该结算单撤回到已生成状态吗？</span>
					</div>
				</div>
			</div>
			<div slot="footer" class="dialog-footer">
				<span class="btnOK mr_20" @click="withDrawalOk">确 定</span>
				<span class="resetBtn" @click="showWithDrawal = false">取 消</span>
			</div>
		</el-dialog>
	</div>
</template>

<script>
import qs from 'qs'
import {
	exportAllBillDetail,
	billShopList,
	shopConfirm,
	shopBatchPay,
	shopBatchInvoice,
	shopRestartCreate,
	shopPay,
	billShopWithDrawal
} from '@/api/bill'
import { fetchInvoiceEnum } from '@/api/invoice'

const common = require('../../../static/tool.js')
export default {
	name: 'BillList',
	data() {
		return {
			id: '',
			ids: '',
			index: '',
			sn: '',
			message: '',
			windowSizeHeight: document.documentElement.clientHeight, //浏览器可视化窗口的大小
			screenHeight: document.documentElement.clientHeight,
			manageInfo: JSON.parse(sessionStorage.getItem('manageInfo')), //登录信息
			url: common.url,
			head_url: common.head_url,
			//搜索对应值
			s_sn: '',
			s_shop_id: '', //店铺id
			s_shop_name: '', //店铺名
			s_status: ['10', '20', '70'],
			s_invoice_status: '',
			s_time_type: '1',
			ruleForm: {
				bill_date_start: '',
				bill_date_end: '',
				date1: '', //开始时间
				date2: '' //结束时间
			},
			invoiceStatus: [], //搜索发票状态
			cityList: [], //城市列表
			city_arr: '',
			city_id: '',
			city_name: '',
			demandList: [], //人才结算单列表
			shopList: [], //店铺列表
			multipleSelection: [], //选中的序号集合
			alltotal: 0,
			//向分页组件传值
			total: 0, //总数量
			pageNum: 1, //当前页
			pageSizeNow: 20,
			// 回款确认-弹框
			diaTitle: '',
			ShowHk: false,
			ShowQr: false,
			remark: '', //备注内容
			// 操作记录-弹框
			cordTicket: false,
			agent_id: '',
			agent_reset: 0,
			statistics: {
				accept: 0,
				pay: 0,
				created: 0
			},
			qrType: '', //批量处理类型
			qrAll: '', //批量处理选中信息
			showWithDrawal: false,
			withDrawalSn: ''
		}
	},
	created() {
		this.ruleForm.date1 = this.$moment().subtract('days', 7).format('YYYY-MM-DD') + ' 00:00:00'
		this.ruleForm.date2 = this.$moment().format('YYYY-MM-DD') + ' 23:59:59'

		if (this.$route.query.sn) {
			this.s_sn = this.$route.query.sn //接收传参
			this.ruleForm.date1 = ''
			this.ruleForm.date2 = ''
		} else {
			this.s_sn = '' //接收传参
		}
	},
	mounted() {
		console.log(this.$route.query)
		this.getInvoiceEnum()
	},
	methods: {
		// 获取搜索发票状态
		async getInvoiceEnum() {
			try {
				const res = await fetchInvoiceEnum({
					type: 'status'
				})
				this.invoiceStatus = res.status.filter(x => [10, 50].includes(x.code))
				this.invoiceStatus.push({ code: 0, name: '未开票' })
			} catch (error) {
				console.log('error', error)
			}
		},
		// 待支付”状态可操作【撤回】
		goRecall(data) {
			this.showWithDrawal = true
			this.withDrawalSn = data.sn
		},
		// 撤回确认
		async withDrawalOk() {
			try {
				const res = await billShopWithDrawal({
					sn: this.withDrawalSn
				})
				this.showWithDrawal = false

				this.$message.success('操作成功！')
				this.listShop()
			} catch (error) {
				console.log('error', error)
			}
		},
		async downloadDetail() {
			if (!this.s_shop_name) {
				this.s_shop_id = ''
			}
			if (this._exportExceed) {
				return this.$message.error(this._exportMsg)
			}

			if (this.ruleForm.bill_date_start && !this.ruleForm.bill_date_end) {
				this.$message.error('结算单结束日期不可为空！')
				return
			}
			if (!this.ruleForm.bill_date_start && this.ruleForm.bill_date_end) {
				this.$message.error('结算单开始日期不可为空！')
				return
			}
			try {
				let params = {
					token: JSON.parse(sessionStorage.getItem('manageInfo')).token,
					sn: this.s_sn,
					shop_id: this.s_shop_id,
					city_id: this.city_id,
					status: this.s_status.join(),
					invoice_status: this.s_invoice_status,
					time_type: this.s_time_type,
					bill_date_start: this.ruleForm.bill_date_start ? this.ruleForm.bill_date_start + ' 00:00:00' : '',
					bill_date_end: this.ruleForm.bill_date_end ? this.ruleForm.bill_date_end + ' 23:59:59' : '',
					start_time: this.ruleForm.date1,
					end_time: this.ruleForm.date2,
					operation: 'export'
				}
				window.location.href = this.url + '/billShop/exportAllDetail?' + qs.stringify(params)
			} catch (err) {}
		},
		chengeCity() {
			let [id, name] = this.city_arr.split('|')
			this.city_id = id.toString()
			this.city_name = name.toString()
			this.s_shop_id = ''
			this.s_shop_name = ''

			this.listUser() //店铺列表
		},
		async listShop() {
			//导出明细-数量统计
			//获取商户结算单列表
			if (!this.s_shop_name) {
				this.s_shop_id = ''
			}
			if (!this.ruleForm.date1) {
				this.ruleForm.date1 = ''
			}
			if (!this.ruleForm.date2) {
				this.ruleForm.date2 = ''
			}
			if (!this.city_name) {
				this.city_id = ''
			}

			if (this.ruleForm.bill_date_start && !this.ruleForm.bill_date_end) {
				this.$message.error('结算单结束日期不可为空！')
				return
			}
			if (!this.ruleForm.bill_date_start && this.ruleForm.bill_date_end) {
				this.$message.error('结算单开始日期不可为空！')
				return
			}

			let obj = {
				sn: this.s_sn,
				city_id: this.city_id,
				shop_id: this.s_shop_id,
				status: this.s_status.join(),
				invoice_status: this.s_invoice_status,
				time_type: this.s_time_type,
				bill_date_start: this.ruleForm.bill_date_start ? this.ruleForm.bill_date_start + ' 00:00:00' : '',
				bill_date_end: this.ruleForm.bill_date_end ? this.ruleForm.bill_date_end + ' 23:59:59' : '',
				start_time: this.ruleForm.date1,
				end_time: this.ruleForm.date2,
				agent_id: this.agent_id
			}

			let ret = await billShopList({
				pageSize: this.pageSizeNow,
				page: this.pageNum,
				...obj
			})
			if (ret.list.length) {
				this.demandList = ret.list
				this.total = ret.count
			} else {
				this.demandList = []
				this.total = 0
				this.statistics.accept = 0
				this.statistics.pay = 0
				this.statistics.created = 0
			}
			//底部统计数据
			this.statistics.accept = ret.accept
			this.statistics.pay = ret.pay
			this.statistics.created = ret.created
			// 获取导出的数量
			let data = await exportAllBillDetail({
				token: JSON.parse(sessionStorage.getItem('manageInfo')).token,
				...obj,
				operation: 'get_count',
				method: 'post'
			})

			this.alltotal = data.count
			this._exportMsg = data.msg
			this._exportExceed = data.isExceed
		},
		listUser() {
			//获取商铺列表
			let fn = new FormData()
			fn.append('sign_status', 30) //已合作的店铺
			fn.append('agent_id', this.agent_id) //启用的店铺
			fn.append('city_id', this.city_id)
			this.$http.post(this.url + '/shop/getListForSearch', fn).then(
				res => {
					if (res.data.msg == '查询成功' || res.data.code == '200') {
						if (res.data.data != null) {
							res.data.data.list.forEach(item => {
								item.value = item.name
							})
							this.shopList = res.data.data.list
						} else {
							this.shopList = []
						}
					} else if (res.data.code == '8886') {
						//code   8886  登录过期
						sessionStorage.clear()
						this.$alert('登录已过期，请重新登录 !', '提示', {
							confirmButtonText: '确定',
							callback: action => {
								window.location = 'login.html'
							}
						})
						return
					} else {
						this.$message.error(res.data.msg)
						return
					}
				},
				res => {
					this.$message.error('网络错误！')
					return
				}
			)
		},
		//分页组件->子组件传值
		onChildValue(item) {
			this.pageNum = item[0]
			this.pageSizeNow = item[1]
			this.listShop()
		},
		//重置
		async resetBtn() {
			this.resetData() //重置请求数据
		},
		//重置请求数据
		resetData() {
			this.pageNum = 1
			this.s_sn = ''
			this.s_shop_id = ''
			this.s_shop_name = ''
			this.s_status = ['10', '20', '70']
			this.s_invoice_status = ''
			this.s_time_type = '1'
			this.ruleForm.bill_date_start = ''
			this.ruleForm.bill_date_end = ''
			this.ruleForm.date1 = this.$moment().subtract('days', 7).format('YYYY-MM-DD') + ' 00:00:00'
			this.ruleForm.date2 = this.$moment().format('YYYY-MM-DD') + ' 23:59:59'
			this.agent_reset += 1
		},
		//获取选中行的id
		handleSelectionChange(val) {
			//获取用户的选中
			this.multipleSelection = []
			val.forEach(item => {
				let paging = {
					sn: item.sn,
					status: item.status,
					invoice_status: item.invoice_status
				}
				this.multipleSelection.push(paging)
			})
			this.multipleSelection = Array.from(new Set(this.multipleSelection))
		},
		//设置表格复选框禁用
		checkboxT(row, index) {
			if (
				//待确认，已确认，未开发票
				row.status == '10' ||
				row.status == '20' ||
				row.invoice_status == '2'
			) {
				return true
			} else {
				return false
			}
		},
		//多行的回款或者开票   1:批量已回款 1:批量已开票 3:批量确认
		async batchPay(e) {
			let fn = new FormData()
			let all = this.multipleSelection
			this.remark = ''
			if (all.length == 0) {
				this.$message.error('请勾选相关列表')
				return
			}

			try {
				if (e == 1) {
					this.diaTitle = '回款确认'
					this.ShowQr = true
					this.qrType = e
					this.qrAll = all
					return
					//批量已回款
				} else if (e == 3) {
					this.diaTitle = '结算单确认'
					this.ShowQr = true
					this.qrType = e
					this.qrAll = all
					return
					//批量确认
				}

				this.$message.success('操作成功！')
				this.listShop()
				this.hiddenRY()
			} catch (err) {}
		},
		// 回款确认
		Hk(row) {
			this.sn = row.sn
			this.diaTitle = '回款确认'
			this.ShowHk = true
		},
		//确认结算单
		Qr(row) {
			this.rowsDate = row
			this.diaTitle = '结算单确认'
			this.ShowQr = true
		},
		//跳转查看列表
		goToList(row) {
			if (row.status == 70) {
				//异常状态-跳转任务列表
				this.$router.push({
					path: '/tasklist',
					query: {
						bill_task_sn: row.detail.toString(),
						bill_status: 1,
						city_id: row.city_id,
						city_name: row.city_name
					}
				})
				return
			}
			this.$router.push({
				path: '/ShopPayDetail',
				query: {
					bill_shop_sn: row.sn
				}
			})
		},
		//重新生成
		async regenerate(row) {
			let ret = await this.$confirm('确定要重新生成吗？', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			})
			if (ret === 'cancel') return

			try {
				await shopRestartCreate({
					sn: row.sn
				})
				this.$message.success('重新生成成功！')
				this.listShop()
			} catch (err) {}
		},
		// 操作记录
		goTorecord(e) {
			// this.resetData()
			this.ids = e.id
			this.message = e.log //行数据
			this.cordTicket = true
			this.diaTitle = '操作记录'
		},
		//隐藏所有的弹框
		hiddenRY() {
			this.remark = ''
			this.ShowHk = false
			this.ShowQr = false
			this.cordTicket = false
		},

		// 确认结算单
		async addQrBtn() {
			if (this.remark == '') {
				this.$message.error('请填写必填项')
				return
			}
			if (this.qrType == 3) {
				//批量确认
				await shopConfirm({
					data: JSON.stringify(this.qrAll),
					remark: this.remark
				})
			} else if (this.qrType == 2) {
				//批量已开票
				await shopBatchInvoice({
					data: JSON.stringify(this.qrAll),
					remark: this.remark
				})
			} else if (this.qrType == 1) {
				//批量已回款
				await shopBatchPay({
					data: JSON.stringify(this.qrAll),
					remark: this.remark
				})
			} else {
				let obj = [
					{
						sn: this.rowsDate.sn,
						status: this.rowsDate.status,
						invoice_status: this.rowsDate.invoice_status
					}
				]
				await shopConfirm({
					data: JSON.stringify(obj),
					remark: this.remark
				})
			}

			this.$message.success('操作成功！')
			this.listShop()
			this.hiddenRY()
		},
		//已回款
		async addCxBtn() {
			if (this.remark == '') {
				this.$message.error('请填写必填项')
				return
			}

			try {
				await shopPay({
					sn: this.sn, //结算单sn
					remark: this.remark //备注
				})

				this.$message.success('操作成功！')
				setTimeout(() => {
					this.listShop()
				}, 1000)
				this.hiddenRY()
			} catch (err) {}
		},
		shearchBtn() {
			// 搜索
			this.pageNum = 1
			this.listShop()
		},
		//店铺的自动完成
		querySearch(queryString, cb) {
			var restaurants = this.shopList
			var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants
			// 调用 callback 返回建议列表的数据
			cb(results)
		},
		createFilter(queryString) {
			return restaurant => {
				return restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
			}
		},
		handleSelect(item) {
			this.s_shop_id = item.id
		},
		//店铺结算单-导出
		downloadOrder(ev) {
			if (this.ruleForm.bill_date_start && !this.ruleForm.bill_date_end) {
				this.$message.error('结算单结束日期不可为空！')
				return
			}
			if (!this.ruleForm.bill_date_start && this.ruleForm.bill_date_end) {
				this.$message.error('结算单开始日期不可为空！')
				return
			}

			let obj = {
				token: JSON.parse(sessionStorage.getItem('manageInfo')).token,
				sn: this.s_sn,
				shop_id: this.s_shop_id,
				city_id: this.city_id,
				status: this.s_status.join(),
				invoice_status: this.s_invoice_status,
				time_type: this.s_time_type,
				bill_date_start: this.ruleForm.bill_date_start ? this.ruleForm.bill_date_start + ' 00:00:00' : '',
				bill_date_end: this.ruleForm.bill_date_end ? this.ruleForm.bill_date_end + ' 23:59:59' : '',
				start_time: this.ruleForm.date1,
				end_time: this.ruleForm.date2,
				agent_id: this.agent_id
			}
			let param = $.param(obj)
			window.location.href = this.url + '/billShop/exportBillList?' + param
		},
		//店铺应收结算单明细-导出
		downloadOrdermini(row) {
			let obj = {
				token: JSON.parse(sessionStorage.getItem('manageInfo')).token,
				bill_shop_sn: row.sn
			}
			let param = $.param(obj)
			window.location.href = this.url + '/billShop/exportPayDetail?' + param
		},
		setValue(arrVal) {
			this.agent_id = arrVal.agent_id
			this.cityList = arrVal.city_list
			this.city_arr = `${this.cityList[0].id}|${this.cityList[0].name}`
			this.city_id = this.cityList[0].id
			this.city_name = this.cityList[0].name
			this.s_shop_id = this.$route.query.shop_id || ''
			this.s_shop_name = this.$route.query.shop_name || ''

			this.listUser() //店铺列表
			this.listShop()
		}
	},
	filters: {}
}
</script>

<style scoped>
.search_box {
	width: 790px;
}
.auditCentent .labels {
	min-height: 100px;
}
.auditCentent .labels .labels_label {
	float: left;
	cursor: pointer;
}
.check_label {
	background: var(--purple4);
	color: #fff;
	border: none;
}
.pdf {
	width: 860px;
	height: 600px;
}
.main_user {
	background: var(--zfy-red);
	color: #fff;
	text-decoration: none;
	padding: 2px 4px;
	border-radius: 4px;
}
@media (max-width: 767.78px) {
	.titleBox {
		height: 40px;
	}
}

.row-info {
	padding: 10px 0;
}
.auditCentent {
	width: 90%;
	margin: 0 auto;
}

.auditCentent button {
	width: 82px;
}

.timeline {
	height: 30px;
	line-height: 30px;
	margin-bottom: 20px;
}

.timeline span {
	margin-left: 10px;
}
</style>



// WEBPACK FOOTER //
// src/components/billshop/List.vue